/**
 *    @file       main.cpp
 *
 *    @brief      
 *    @details
 *
 *    @version    1.0
 *    @date       12/11/2012 11:06:20 AM
 *
 *    @author     Theophilus, wangtf418@gmail.com
 */
#include <stdio.h>
#include "maintaincmd.h"
#include "sockbase.h"
#include "toolkit.h"
#include "udpclient.h"

class logswitch_client : public udpclient<maintain_cmdhead, logswitch_cmdbody, maintain_cmdhead, logswitchres_cmdbody>
{
public:
	logswitch_client(const std::string &srvip, bf_ushort_t srvport)
		: udpclient<maintain_cmdhead, logswitch_cmdbody, maintain_cmdhead, logswitchres_cmdbody> (srvip, srvport)
	{

	}

public:
	virtual bf_int_t process(maintain_cmdhead &reqhead, logswitch_cmdbody &reqbody, maintain_cmdhead &reshead, logswitchres_cmdbody &resbody)
	{
		printf("rescmd=%u, logtype=%u, logflag=%d, ret=%d\n", reshead.m_cmdid, reqbody.m_logtype, reqbody.m_logtype, resbody.m_result);
		return BF_OK;
	}

};

int main(bf_int_t argc, bf_char_t *argv[])
{
	if (argc != 5)
	{
		printf("Usage:%s srvip srvport logtype logflag\n", argv[0]);
		return BF_ERROR;
	}

	maintain_cmdhead head;
	head.m_cmdid = MAINTAIN_CMD_TYPE_LOGSWITCH;
	logswitch_cmdbody body;

	body.m_logtype = toolkit::str2int(argv[3]);
	body.m_logflag = toolkit::str2int(argv[4]);
	logswitch_client client(argv[1], toolkit::str2int(argv[2]));
	bf_int_t ret = client.init();
	if (ret != BF_OK)
	{
		return BF_ERROR;
	}
	ret = client.send_and_recv(head, body);
	if (ret != BF_OK)
	{
		printf("send_and_recv fail\n");
		return BF_ERROR;
	}

	return BF_OK;
}


